package data_retrieval;

import info.androidhive.slidingmenu.R;

import java.util.List;

import mindshare.LoadContent;

import org.apache.http.NameValuePair;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Base64;
import android.util.Log;
import android.widget.ImageView;

public class GetPicture extends LoadContent {
	String blob;

	public GetPicture(Context context, List<NameValuePair> param, String data) {
		super(context, param, data);
	}

	@Override
	protected String doInBackground(String... args) {
		JSONObject json = jParser.makeHttpRequest("http://mindshare.comli.com/getImage.php", param);
		contentList.clear();
		try {
			blob = json.getString("image");
			Log.d("ProfileConf", "blob: " + blob);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return null;
	}

	@Override
	protected void onPostExecute(String file_url) {
		//If an image is retrieved from the server, set ivPicture src to it 
		if (!blob.equals("")){
			ImageView ivPic = (ImageView) ((Activity) c).findViewById(R.id.ivPicture);
			byte[] decodedString = Base64.decode(blob, Base64.DEFAULT);
			Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
			ivPic.setImageBitmap(decodedByte);
		}
		pDialog.dismiss();
	}

}